SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for uaa_customer_function
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_customer_function` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `customer_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '客户id',
    `function_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '功能id',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa客户与功能关联表';

-- ----------------------------
-- Records of uaa_customer_function
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for uaa_function
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_function` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `pid` bigint(11) NOT NULL DEFAULT '0' COMMENT '父id',
    `name` varchar(30) NOT NULL DEFAULT '' COMMENT '功能名称',
    `url` varchar(100) NOT NULL DEFAULT '' COMMENT '后端为接口，前端为跳转url',
    `type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '类型（目录1，页面2，按钮3）',
    `sort` int(4) NOT NULL DEFAULT '0' COMMENT '排序（正序）',
    `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态（1上架，2下架）',
    `level` tinyint(4) NOT NULL DEFAULT '0' COMMENT '等级',
    `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除（删除1，不删除0）',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa功能表';

-- ----------------------------
-- Records of uaa_function
-- ----------------------------
BEGIN;
INSERT INTO `uaa_function` (id, pid, name, url, status) select 1, 0, '模块管理', '/api/uaa/function/**', 1 WHERE NOT EXISTS(select id from uaa_function where id = 1);
INSERT INTO `uaa_function` (id, pid, name, url, status) select 2, 0, '套餐管理', '/api/uaa/setMeal/**', 1 WHERE NOT EXISTS(select id from uaa_function where id = 2);
INSERT INTO `uaa_function` (id, pid, name, url, status) select 3, 0, '客户管理', '/api/uaa/customer/**', 1 WHERE NOT EXISTS(select id from uaa_function where id = 3);
INSERT INTO `uaa_function` (id, pid, name, url, status) select 4, 0, '用户管理', '/api/uaa/userInfo/**', 1 WHERE NOT EXISTS(select id from uaa_function where id = 4);
INSERT INTO `uaa_function` (id, pid, name, url, status) select 5, 0, '角色管理', '/api/uaa/roleInfo/**', 1 WHERE NOT EXISTS(select id from uaa_function where id = 5);
INSERT INTO `uaa_function` (id, pid, name, url, status, type, sort, level) select 6, 0, '初始目录', '-', 1, 1, 1, 1 WHERE NOT EXISTS(select id from uaa_function where id = 6);
COMMIT;

-- ----------------------------
-- Table structure for uaa_login_info
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_login_info` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `user_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '用户id',
    `account` varchar(20) NOT NULL DEFAULT '' COMMENT '账号',
    `password` varchar(100) NOT NULL DEFAULT '' COMMENT '密码',
    `already_first_login` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否已经首次登陆（0未首次登陆 1已经首次登陆）',
    `last_login_time` datetime DEFAULT NULL COMMENT '最近一次登录时间',
    `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除（删除1，不删除0）',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa登陆';

-- ----------------------------
-- Records of uaa_login_info
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for uaa_manage_info
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_manage_info` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `name` varchar(30) NOT NULL DEFAULT '' COMMENT '姓名',
    `avatar` varchar(100) DEFAULT '' COMMENT '头像',
    `type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '类型（平台管理员0，开发者1）',
    `account` varchar(20) NOT NULL DEFAULT '' COMMENT '账号',
    `password` varchar(100) NOT NULL DEFAULT '' COMMENT '密码',
    `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除（删除1，不删除0）',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa管理员表';

-- ----------------------------
-- Records of uaa_manage_info
-- ----------------------------
BEGIN;
INSERT INTO `uaa_manage_info` (id, name, avatar, type, account, password) select 1, '平台管理员', 'https://rd-demo.oss-cn-hangzhou.aliyuncs.com/01112012ajf.JPG', 0, 'platform', '$2a$10$HtQ.QzfwQRASvADC6eDrce9RcxAy3oqxLYAf7ZRzGz8Va9.J6jo8y'  WHERE NOT EXISTS(select id from uaa_manage_info where id = 1);
INSERT INTO `uaa_manage_info` (id, name, avatar, type, account, password) select 2, '开发者', 'https://rd-demo.oss-cn-hangzhou.aliyuncs.com/01112012ajf.JPG', 1, 'dev', '$2a$10$UkaDEzl89yocVKUWbEMVle1HdEaVy/2LWE7WWY31sNPKII0zj9QQG'  WHERE NOT EXISTS(select id from uaa_manage_info where id = 2);
COMMIT;

-- ----------------------------
-- Table structure for uaa_role_function
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_role_function` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `function_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '功能id',
    `role_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '角色id',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa角色与功能关联表';

-- ----------------------------
-- Records of uaa_role_function
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for uaa_role_info
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_role_info` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `customer_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '公司id',
    `name` varchar(30) NOT NULL DEFAULT '' COMMENT '角色名称',
    `remark` varchar(200) NOT NULL DEFAULT '' COMMENT '备注',
    `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除（删除1，不删除0）',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa角色表';

-- ----------------------------
-- Records of uaa_role_info
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for uaa_set_meal
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_set_meal` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '套餐id',
    `name` varchar(30) NOT NULL DEFAULT '' COMMENT '套餐名称',
    `duration` varchar(10) NOT NULL DEFAULT '' COMMENT '时长',
    `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除（删除1，不删除0）',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa套餐表';

-- ----------------------------
-- Records of uaa_set_meal
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for uaa_set_meal_function
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_set_meal_function` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `set_meal_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '套餐id',
    `function_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '功能id',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa套餐和功能关联表';

-- ----------------------------
-- Records of uaa_set_meal_function
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for uaa_customer_info
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_customer_info` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `pid` bigint(11) NOT NULL DEFAULT '0' COMMENT '父id',
    `type` varchar(32) NOT NULL DEFAULT '' COMMENT '类型，详情请见data_item表organizationType',
    `account` varchar(20) NOT NULL DEFAULT '' COMMENT '管理员账号',
    `name` varchar(128) NOT NULL DEFAULT '' COMMENT '公司名称',
    `industry` varchar(128) NOT NULL DEFAULT '' COMMENT '所属行业',
    `social_credit_code` varchar(64) NOT NULL DEFAULT '' COMMENT '统一社会信用代码',
    `stock_code` varchar(128) NOT NULL DEFAULT '' COMMENT '股票代码',
    `address` varchar(255) NOT NULL DEFAULT '' COMMENT '地点',
    `registered_capital` int(11) NOT NULL DEFAULT '0' COMMENT '注册资本',
    `legal_person_name` varchar(30) NOT NULL DEFAULT '' COMMENT '法人姓名',
    `legal_person_id_card` varchar(30) NOT NULL DEFAULT '' COMMENT '法人身份证',
    `email` varchar(64) NOT NULL DEFAULT '' COMMENT '邮箱',
    `contact_name` varchar(30) NOT NULL DEFAULT '' COMMENT '联系人姓名',
    `contact_phone` varchar(20) NOT NULL DEFAULT '' COMMENT '联系人手机号',
    `business_license_resources` varchar(128) NOT NULL DEFAULT '' COMMENT '营业执照',
    `shareholder_structure` varchar(500) NOT NULL DEFAULT '' COMMENT '股东结构（格式为图片）',
    `financing_needs_amount` int(11) NOT NULL DEFAULT '0' COMMENT '融资需求额度',
    `annual_income` int(11) NOT NULL DEFAULT '0' COMMENT '近期年收入',
    `introduction` varchar(1000) NOT NULL DEFAULT '' COMMENT '简介',
    `credit_rating` int(11) DEFAULT NULL COMMENT '评级等级',
    `rating_time` datetime DEFAULT NULL COMMENT '评级时间',
    `report_id` bigint(20) DEFAULT NULL COMMENT '评级报告id',
    `attachment` varchar(300) NOT NULL DEFAULT '' COMMENT '附件',
    `last_login_time` datetime DEFAULT NULL COMMENT '最近一次登录时间',
    `extra` varchar(255) NOT NULL DEFAULT '' COMMENT '扩展信息',
    `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除（删除1，不删除0）',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
     PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='uaa客户信息表';

-- ----------------------------
-- Table structure for customer_set_meal
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_customer_set_meal` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `customer_id` bigint(11) NOT NULL DEFAULT 0 COMMENT '客户id',
    `set_meal_id` bigint(11) NOT NULL DEFAULT 0 COMMENT '套餐id',
    `status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '状态（1生效，2不生效）',
    `timeout` datetime NOT NULL COMMENT '超时时间',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa客户和套餐关联表';

-- ----------------------------
-- Table structure for uaa_user_info
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_user_info` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `customer_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '公司id',
    `name` varchar(30) NOT NULL DEFAULT '' COMMENT '姓名',
    `phone` varchar(20) NOT NULL DEFAULT '' COMMENT '手机号',
    `avatar` varchar(100) NOT NULL DEFAULT '' COMMENT '头像',
    `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态（初始状态0，启用1，停用-1）',
    `type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '类型（管理员0，员工1）',
    `gender` tinyint(4) NOT NULL DEFAULT '0' COMMENT '性别（未知0，1男，2女）',
    `remark` varchar(30) NOT NULL DEFAULT '' COMMENT '备注',
    `terminal` tinyint(4) NOT NULL DEFAULT '0' COMMENT '终端类型 1pc 2h5',
    `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除（删除1，不删除0）',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa用户信息';

-- ----------------------------
-- Records of uaa_user_info
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for uaa_user_role
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_user_role` (
    `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
    `role_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '角色id',
    `user_id` bigint(11) NOT NULL DEFAULT '0' COMMENT '用户id',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='uaa用户与角色关联表';

-- ----------------------------
-- Records of uaa_user_role
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for uaa_data_item
-- ----------------------------
CREATE TABLE IF NOT EXISTS `uaa_data_item` (
     `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
     `pid` bigint(20) NOT NULL DEFAULT '0' COMMENT '父id',
     `code` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '编码',
     `name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '名称',
     `value` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '值',
     `sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序值',
     `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否是默认值（1是，0不是）',
     `is_delete` tinyint(1) DEFAULT '0' COMMENT '是否删除（1已删除，0未删除）',
     `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
     `updated_at` datetime DEFAULT NULL COMMENT '更新时间',
     PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='uaa数据项信息表';

BEGIN;
INSERT INTO `uaa_data_item` (`id`, `pid`, `code`, `name`, `value`) select 1, 0, 'organizationType', 'enterprise', '企业' WHERE NOT EXISTS(select id from uaa_data_item where id = 1);
INSERT INTO `uaa_data_item` (`id`, `pid`, `code`, `name`, `value`) select 2, 0, 'organizationType', 'organ', '机关' WHERE NOT EXISTS(select id from uaa_data_item where id = 2);
INSERT INTO `uaa_data_item` (`id`, `pid`, `code`, `name`, `value`) select 3, 0, 'organizationType', 'business_unit', '事业单位' WHERE NOT EXISTS(select id from uaa_data_item where id = 3);
INSERT INTO `uaa_data_item` (`id`, `pid`, `code`, `name`, `value`) select 4, 0, 'organizationType', 'social_groups', '社会团体' WHERE NOT EXISTS(select id from uaa_data_item where id = 4);
INSERT INTO `uaa_data_item` (`id`, `pid`, `code`, `name`, `value`) select 5, 0, 'organizationType', 'other', '其他组织' WHERE NOT EXISTS(select id from uaa_data_item where id = 5);
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;